package src;

import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.awt.geom.NoninvertibleTransformException;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;

import com.lyfam.game.behaviosr.steering.ISteeringBehavior;
import com.lyfam.game.behaviosr.steering.ObstacleAvoidanceBehavior;
import com.lyfam.game.behaviosr.steering.SteeringEngine;
import com.lyfam.game.behaviosr.steering.WanderingBehavior;
import com.lyfam.game.entity.Obstacle;
import com.lyfam.game.entity.Vehicle;
import com.lyfam.game.geometry.Vector2D;

import processing.core.PApplet;

public class ObstacleAvoidance extends PApplet
{
	private List<Obstacle> obstacles = new ArrayList<Obstacle>(2);
	private Vehicle veh;
	ISteeringBehavior obstacleAvoidance;

	public void setup()
	{
		setSize(500, 500);
		colorMode(RGB, 100);

		Vector2D v = new Vector2D(0, 0);
		veh = new Vehicle(v, new Vector2D(0.1f,0.1f), 2, 3f);
		SteeringEngine engine = new SteeringEngine();
		veh.setMass(3);
		veh.setSize(10);
		obstacleAvoidance = new ObstacleAvoidanceBehavior(veh, obstacles, g);
		engine.addBehavior(obstacleAvoidance);
		engine.addBehavior(new WanderingBehavior(veh, g, random(10, 40), random(20, 70), random(0.05f, 4.5f)));
		
		veh.setSteeringengine(engine);

		Obstacle obs = new Obstacle(new Vector2D(width/2, height/2));
		obs.setSize(20);
		obstacles.add(obs);
		
		obs = new Obstacle(new Vector2D(100, 300));
		obs.setSize(35);
		obstacles.add(obs);

		smooth();
		frameRate(60);
	}

	public void draw()
	{
		background(100);
		noFill();
		
		for (Obstacle obs : obstacles)
		{
			obs.render(g);
		}
		
		veh.render(g);		
		veh.update();
	}

	@Override
	public void mouseClicked(MouseEvent arg0)
	{
		obstacles.get(1).getPosition().setX(arg0.getX());
		obstacles.get(1).getPosition().setY(arg0.getY());
	}
	
	
}
